Guest User

Untitled

a guest
Nov 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.48 KB | None | 0 0
  1. {
  2. [Activity(Label = "@string/AppTitle", ConfigurationChanges = ConfigChanges.Orientation)]
  3. public class RemainsActivity : BaseTabActivity
  4. {
  5. internal class Parameters
  6. {
  7. // Входные параметры
  8. internal static Guid VisitID;
  9. internal static Guid ShopID;
  10.  
  11.  
  12. internal static Guid savedInvoiceID = TypeExtra.GuidNull;
  13. internal static Guid ProductTreeID;
  14. internal static TreeType TreeType;
  15. internal static List<Guid> TempInvoices = new List<Guid>();
  16.  
  17.  
  18. internal static bool UpdateCategoryProducts;
  19. internal static bool UpdateInvoiceProducts;
  20.  
  21. private static List<Product> categoryProducts = new List<Product>();
  22. internal static List<Product> CategoryProducts
  23. {
  24. get { return categoryProducts; }
  25. set { categoryProducts = (value ?? new List<Product>()); } //
  26. }
  27. private static List<Product> invoiceProducts = new List<Product>();
  28. internal static List<Product> InvoiceProducts
  29. {
  30. get { return invoiceProducts; }
  31. set { invoiceProducts = (value ?? new List<Product>()); } //
  32. }
  33.  
  34. private static List<InvoiceProduct> lastPrices = new List<InvoiceProduct>();
  35. internal static List<InvoiceProduct> LastPrices
  36. {
  37. get { return lastPrices; }
  38. set { lastPrices = (value ?? new List<InvoiceProduct>()); } //
  39. }
  40.  
  41. internal static TabHost TabHost;
  42.  
  43. internal static void Set(Guid visitID, Guid shopID)
  44. {
  45. Reset();
  46.  
  47. VisitID = visitID;
  48. ShopID = shopID;
  49. Settings.User.CurrentInvoiceType = InvoiceType.Enum.MerchCurrentRemainsAndPrices;
  50. }
  51. internal static void Reset()
  52. {
  53. TempInvoices.Clear();
  54. CategoryProducts.Clear();
  55. InvoiceProducts.Clear();
  56.  
  57. ProductTreeID = TypeExtra.GuidNull;
  58. UpdateCategoryProducts = false;
  59. UpdateInvoiceProducts = false;
  60. }
  61. }
  62.  
  63. private const int TabWidgetHeightDP = 35;
  64. private const string categoryTabID = "Category";
  65. private const string invoiceTabID = "Invoice";
  66.  
  67.  
  68. private TabHost.TabSpec categoryWidget = null;
  69. private TabHost.TabSpec invoiceWidget = null;
  70.  
  71. protected override void OnCreate(Bundle bundle)
  72. {
  73. base.OnCreate(bundle);
  74. RemainsActivity.Parameters.savedInvoiceID = TypeExtra.GuidNull;
  75. if (bundle != null)
  76. if (RemainsActivity.Parameters.VisitID == null)
  77. {
  78.  
  79. if (bundle.ContainsKey("Parameters.savedInvoiceID"))
  80. RemainsActivity.Parameters.savedInvoiceID = new Guid(bundle.GetString("Parameters.savedInvoiceID"));
  81. string ID;
  82.  
  83. ID = bundle.GetString("Parameters.ProductTreeID");
  84. if (!string.IsNullOrEmpty(ID))
  85. {
  86. bundle.Remove("Parameters.ProductTreeID");
  87. RemainsActivity.Parameters.ProductTreeID = new Guid(ID);
  88. }
  89.  
  90. ID = bundle.GetString("Parameters.VisitID");
  91. if (!string.IsNullOrEmpty(ID))
  92. {
  93. string ShopID = bundle.GetString("Parameters.ShopID");
  94. RemainsActivity.Parameters.Set(new Guid(ID), new Guid(ShopID));
  95. bundle.Remove("Parameters.VisitID");
  96. bundle.Remove("Parameters.ShopID");
  97. }
  98. ID = bundle.GetString("Parameters.ProductTreeID");
  99. if (!string.IsNullOrEmpty(ID))
  100. {
  101. bundle.Remove("Parameters.ProductTreeID");
  102. RemainsActivity.Parameters.ProductTreeID = new Guid(ID);
  103. }
  104.  
  105. }
  106.  
  107. SetContentView(Resource.Layout.RemainsActivity);
  108.  
  109. // Select
  110. var intent = new Intent(this, typeof(RemainsActivity_CategoryTab));
  111. intent.AddFlags(ActivityFlags.NewTask);
  112. categoryWidget = TabHost.NewTabSpec(categoryTabID);
  113. categoryWidget.SetIndicator(GetString(Resource.String.TabTitle_Select));
  114. categoryWidget.SetContent(intent);
  115. TabHost.AddTab(categoryWidget);
  116.  
  117. // Invoice
  118. intent = new Intent(this, typeof(RemainsActivity_InvoiceTab));
  119. intent.AddFlags(ActivityFlags.NewTask);
  120. invoiceWidget = TabHost.NewTabSpec(invoiceTabID);
  121. invoiceWidget.SetIndicator(GetString(Resource.String.TabTitle_Remains));
  122. invoiceWidget.SetContent(intent);
  123. TabHost.AddTab(invoiceWidget);
  124.  
  125. for (int i = 0; i < TabHost.TabWidget.ChildCount; i++)
  126. {
  127. //var image = ((RelativeLayout)TabHost.TabWidget.GetChildAt(i)).GetChildAt(0);
  128. //var tv = ((RelativeLayout)TabHost.TabWidget.GetChildAt(i)).GetChildAt(1);
  129.  
  130. //((RelativeLayout)TabHost.TabWidget.GetChildAt(i)).RemoveViewAt(0);
  131. var rl = TabHost.TabWidget.GetChildAt(i);
  132. rl.LayoutParameters.Height = (int)(TabWidgetHeightDP * Resources.DisplayMetrics.Density + 0.5f);
  133. }
  134.  
  135. TabHost.CurrentTab = 0;
  136. TabHost.TabChanged += new EventHandler<Android.Widget.TabHost.TabChangeEventArgs>(TabHost_TabChanged);
  137. Parameters.TabHost = TabHost;
  138. }
  139. protected override void OnRestart()
  140. {
  141. if (Parameters.TabHost != null)
  142. Parameters.TabHost.Dispose();
  143. base.OnRestart();
  144. }
  145.  
  146. protected override void OnSaveInstanceState(Bundle outState)
  147. {
  148. Log.Debug("OnSaveInstanceState Remains Category Tab Activity");
  149.  
  150. if (RemainsActivity.Parameters.VisitID != null)
  151. outState.PutString("Parameters.VisitID", RemainsActivity.Parameters.VisitID.ToString());
  152. if (RemainsActivity.Parameters.ShopID != null)
  153. outState.PutString("Parameters.ShopID", RemainsActivity.Parameters.ShopID.ToString());
  154. if (RemainsActivity.Parameters.ProductTreeID != null)
  155. outState.PutString("Parameters.ProductTreeID", RemainsActivity.Parameters.ProductTreeID.ToString());
  156. if (Parameters.savedInvoiceID != null)
  157. outState.PutString("Parameters.savedInvoiceID", RemainsActivity.Parameters.savedInvoiceID.ToString());
  158.  
  159. base.OnSaveInstanceState(outState);
  160. }
  161.  
  162. <mobileagent.customcontrols.ProductTreeView
  163. android:id="@+id/RemainsActivity_CategoryTab_ProductTreeView"
  164. android:layout_height="wrap_content"
  165. android:layout_width="match_parent" />
  166.  
  167. `<?xml version="1.0" encoding="utf-8"?>
  168. <LinearLayout xmlns:android=""
  169. xmlns:app=""
  170. android:tag="RemainsActivity_CategoryTab"
  171. android:id="@+id/RemainsActivity_CategoryTab_RootLayout"
  172. android:layout_width="match_parent"
  173. android:layout_height="match_parent"
  174. android:orientation="vertical">
  175. <LinearLayout
  176. android:id="@+id/RemainsActivity_CategoryTab_MainLayout"
  177. android:layout_height="match_parent"
  178. android:layout_width="match_parent"
  179. android:orientation="vertical"
  180. android:layout_weight="1">
  181. <app1.customcontrols.DrawnDataGrid
  182. android:id="@+id/RemainsActivity_CategoryTab_DataGrid"
  183. android:layout_height="match_parent"
  184. android:layout_width="wrap_content"
  185. android:layout_weight="1"
  186. android:tag="RemainsActivity_CategoryTab_DataGrid">
  187. <!-- DataGrid Header-->
  188. <app1.customcontrols.DrawnDataGridHeader
  189. android:layout_width="wrap_content"
  190. android:layout_height="wrap_content">
  191. <app1.customcontrols.DataGridColumn
  192. app:mapping="ProductName"
  193. android:text="@string/ProductName"
  194. android:layout_width="200dp"
  195. android:layout_height="25dp"
  196. style="@style/DataGridHeader.First" />
  197. <app1.customcontrols.DataGridColumn
  198. app:mapping="TotalProductQuantity"
  199. app:format="{FractionInUnitsFormat}"
  200. android:text="@string/Quantity"
  201. android:layout_width="50dp"
  202. android:layout_height="25dp"
  203. app:cellgravity="right"
  204. style="@style/DataGridHeader.Next" />
  205. <app1.customcontrols.DataGridColumn
  206. app:mapping="CustomPrice"
  207. app:format="{0:0.00}"
  208. android:text="@string/Price"
  209. android:layout_width="50dp"
  210. android:layout_height="25dp"
  211. app:cellgravity="right"
  212. style="@style/DataGridHeader.Next" />
  213. </app1.customcontrols.DrawnDataGridHeader>
  214. </app1.customcontrols.DrawnDataGrid>
  215. <!-- Product Info -->
  216. <TextView
  217. android:id="@+id/RemainsActivity_CategoryTab_ProductInfoTextView"
  218. android:hint="@string/Hint_ProductInfo"
  219. android:layout_height="wrap_content"
  220. android:layout_width="match_parent" />
  221. <!-- Edit Text Controls -->
  222. <LinearLayout
  223. android:layout_width="match_parent"
  224. android:layout_height="wrap_content"
  225. android:orientation="horizontal">
  226. <ImageButton
  227. android:src="@drawable/tb_product_tree"
  228. android:scaleType="centerInside"
  229. android:id="@+id/RemainsActivity_CategoryTab_ProductTreeButton"
  230. android:layout_height="@dimen/productTreeButtonSize"
  231. android:layout_width="@dimen/productTreeButtonSize"
  232. android:layout_gravity="center_vertical" />
  233. <EditText
  234. android:text=""
  235. android:hint="@string/Blocks"
  236. android:id="@+id/RemainsActivity_CategoryTab_BlocksEditText"
  237. android:singleLine="true"
  238. android:layout_weight="0.3"
  239. android:numeric="decimal"
  240. android:selectAllOnFocus="true"
  241. android:imeOptions="flagNoExtractUi"
  242. android:layout_height="wrap_content"
  243. android:layout_width="wrap_content" />
  244. <EditText
  245. android:text=""
  246. android:hint="@string/Units"
  247. android:id="@+id/RemainsActivity_CategoryTab_UnitsEditText"
  248. android:singleLine="true"
  249. android:layout_weight="0.3"
  250. android:numeric="decimal"
  251. android:inputType="numberDecimal"
  252. android:digits="0123456789.,"
  253. android:selectAllOnFocus="true"
  254. android:imeOptions="flagNoExtractUi"
  255. android:layout_height="wrap_content"
  256. android:layout_width="wrap_content" />
  257. <EditText
  258. android:text=""
  259. android:hint="@string/Price"
  260. android:id="@+id/RemainsActivity_CategoryTab_PriceEditText"
  261. android:singleLine="true"
  262. android:layout_weight="0.3"
  263. android:numeric="decimal"
  264. android:inputType="numberDecimal"
  265. android:digits="0123456789.,"
  266. android:selectAllOnFocus="true"
  267. android:imeOptions="flagNoExtractUi"
  268. android:layout_height="wrap_content"
  269. android:layout_width="wrap_content" />
  270. </LinearLayout>
  271. <!-- NumPad -->
  272. <app1.customcontrols.NumPad
  273. android:id="@+id/NumPad"
  274. android:layout_height="wrap_content"
  275. android:layout_width="match_parent" />
  276. </LinearLayout>
  277.  
  278. <app1.customcontrols.ProductTreeView
  279. android:id="@+id/RemainsActivity_CategoryTab_ProductTreeView"
  280. android:layout_height="wrap_content"
  281. android:layout_width="match_parent" />
  282. <app1.CustomControls.MenuButtonPanel
  283. android:id="@+id/RemainsActivity_CategoryTab_MenuButtonPanel"
  284. android:layout_height="wrap_content"
  285. android:layout_width="match_parent" />
  286. </LinearLayout>`
  287.  
  288. private bool selected = false;
  289. private Product Selected = null;
  290. private Product InvoiceProduct = null;
  291. //{
  292. // get
  293. // {
  294. // if (productsDataGrid.SelectedIndex == -1)
  295. // return null;
  296. // else
  297. // return categoryProducts[productsDataGrid.SelectedIndex];
  298. // }
  299. //}
  300.  
  301. private DrawnDataGrid dataGrid;
  302. private TextView productInfoTextView;
  303. private ImageButton productTreeButton;
  304.  
  305. private EditText blocksEditText;
  306. private EditText unitsEditText;
  307. private EditText priceEditText;
  308.  
  309. private LinearLayout mainLayout;
  310. private ProductTreeView productTreeView;
  311.  
  312. protected override void OnCreate(Bundle bundle)
  313. {
  314. try
  315. {
  316. base.OnCreate(bundle);
  317.  
  318. if (CheckWasInBackground()) return;
  319.  
  320.  
  321. SetContentView(Resource.Layout.RemainsActivity_CategoryTab);
  322.  
  323. BindMenuButtonClicked(Resource.Id.RemainsActivity_CategoryTab_MenuButtonPanel);
  324.  
  325. dataGrid = FindViewById<DrawnDataGrid>(Resource.Id.RemainsActivity_CategoryTab_DataGrid);
  326. dataGrid.SelectedChanged += new EventHandler(dataGrid_SelectedChanged);
  327.  
  328. productInfoTextView = FindViewById<TextView>(Resource.Id.RemainsActivity_CategoryTab_ProductInfoTextView);
  329.  
  330. productTreeButton = FindViewById<ImageButton>(Resource.Id.RemainsActivity_CategoryTab_ProductTreeButton);
  331. productTreeButton.Click += new EventHandler(OnProductTreeButtonClick);
  332.  
  333. blocksEditText = FindViewById<EditText>(Resource.Id.RemainsActivity_CategoryTab_BlocksEditText);
  334. blocksEditText.TextChanged += new EventHandler<Android.Text.TextChangedEventArgs>(OnQuantityChanged);
  335.  
  336. unitsEditText = FindViewById<EditText>(Resource.Id.RemainsActivity_CategoryTab_UnitsEditText);
  337. unitsEditText.TextChanged += new EventHandler<Android.Text.TextChangedEventArgs>(OnQuantityChanged);
  338.  
  339. priceEditText = FindViewById<EditText>(Resource.Id.RemainsActivity_CategoryTab_PriceEditText);
  340. priceEditText.TextChanged += OnPriceChanged;
  341.  
  342. mainLayout = FindViewById<LinearLayout>(Resource.Id.RemainsActivity_CategoryTab_MainLayout);
  343.  
  344. productTreeView = FindViewById<ProductTreeView>(Resource.Id.RemainsActivity_CategoryTab_ProductTreeView);
  345. productTreeView.TreeItemSelected += new EventHandler(OnTreeItemSelected);
  346. productTreeView.Hide();
  347.  
  348. Init();
  349. OnCreateFinished();
  350. }
  351. catch (Exception ex)
  352. {
  353. Log.Exception(ex);
  354. throw;
  355. }
  356. }
  357.  
  358. private TreeView mTreeView;
  359. private bool mAlternative = false;
  360. private bool loaded = false;
  361.  
  362. internal event EventHandler TreeItemSelected;
  363.  
  364. internal Guid SelectedProductTreeID
  365. {
  366. get { return mTreeView.SelectedID != null ? (Guid)mTreeView.SelectedID : TypeExtra.GuidNull; }
  367. }
  368.  
  369. internal TreeType SelectedTreeType
  370. {
  371. get { return mTreeView.SelectedTreeType; }
  372. }
  373.  
  374. internal string SelectedText
  375. {
  376. get { return SelectedProductTreeID != TypeExtra.GuidNull ? mTreeView.SelectedText : Context.GetString(Resource.String.AllProductTrees); }
  377. }
  378.  
  379. public ProductTreeView(Context context, IAttributeSet attrs) :
  380. base(context, attrs)
  381. {
  382. Init(context, attrs);
  383. }
  384.  
  385. public ProductTreeView(Context context, bool isAlternative, IAttributeSet attrs) :
  386. base(context, attrs)
  387. {
  388. mAlternative = isAlternative;
  389. Init(context, attrs);
  390. }
  391.  
  392. private void Init(Context context, IAttributeSet attrs)
  393. {
  394.  
  395. mHorizontalScrollView = new HorizontalScrollView(context, attrs);
  396. AddView(mHorizontalScrollView, new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent));
  397.  
  398. mTreeView = new TreeView(context, attrs);
  399.  
  400. mHorizontalScrollView.AddView(mTreeView, new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent));
  401.  
  402. mTreeView.SelectedChanged += new EventHandler(treeView_SelectedChanged);
  403. mTreeView.ParentSelectedChanged += new EventHandler(treeView_ParentSelectedChanged);
  404. }
  405.  
  406. Сlass TreeView:
  407.  
  408. public class TreeView : LinearLayout
  409. {
  410. private List<List<ITreeItem>> trees = new List<List<ITreeItem>>();
  411. private Hashtable itemsByID = new Hashtable();
  412. private Hashtable treeIndexesByID = new Hashtable();
  413. private Hashtable treeTypesByTreeIndex = new Hashtable();
  414.  
  415. private TreeViewItem SelectedItem;
  416.  
  417. internal object SelectedID
  418. {
  419. get
  420. {
  421. if (SelectedItem == null)
  422. {
  423. return null;
  424. }
  425. else
  426. {
  427. return SelectedItem.ID;
  428. }
  429. }
  430. }
  431. internal string SelectedText
  432. {
  433. get
  434. {
  435. if (SelectedItem == null)
  436. {
  437. return null;
  438. }
  439. else
  440. {
  441. return SelectedItem.Text;
  442. }
  443. }
  444. }
  445. internal TreeType SelectedTreeType
  446. {
  447. get
  448. {
  449. if (SelectedItem == null)
  450. {
  451. return TreeType.None;
  452. }
  453. else
  454. {
  455. var idx = treeIndexesByID[SelectedItem.ID];
  456. return (TreeType)treeTypesByTreeIndex[idx];
  457. }
  458. }
  459. }
  460.  
  461. internal event EventHandler SelectedChanged;
  462. internal event EventHandler ParentSelectedChanged;
  463.  
  464. #region Colors
  465. protected Color backgroundColorNotSelected = Color.AliceBlue;
  466. protected Color BackgroundColorNotSelected
  467. {
  468. get
  469. {
  470. if (backgroundColorNotSelected == Color.AliceBlue)
  471. {
  472. TypedValue tv = new TypedValue();
  473. Context.Theme.ResolveAttribute(Android.Resource.Attribute.ColorBackground, tv, true);
  474. backgroundColorNotSelected = Resources.GetColor(tv.ResourceId);
  475. }
  476. return backgroundColorNotSelected;
  477. }
  478. }
  479.  
  480. protected Color backgroundColorSelected = Color.AliceBlue;
  481. protected Color BackgroundColorSelected
  482. {
  483. get
  484. {
  485. if (backgroundColorSelected == Color.AliceBlue)
  486. {
  487. TypedValue tv = new TypedValue();
  488. Context.Theme.ResolveAttribute(Android.Resource.Attribute.TextColorSecondaryInverse, tv, true);
  489. backgroundColorSelected = Resources.GetColor(tv.ResourceId);
  490. }
  491. return backgroundColorSelected;
  492. }
  493. }
  494. #endregion
  495.  
  496. public TreeView(Context context, IAttributeSet attrs) :
  497. base(context, attrs)
  498. {
  499. Orientation = Orientation.Vertical;
  500. }
Add Comment
Please, Sign In to add comment