protected override void LoadControlState(object state)
 {
     if (state != null)
     {
         object[] ctlState = (object[])state;
         base.LoadControlState(ctlState[0]);
         _showSumary = (bool)ctlState[1];
         _feeAmount = (string)ctlState[2];
         _custInfo = (Customer)ctlState[3];
         _exchangeNumber = (string)ctlState[4];
         _finish = (bool)ctlState[5];
         _saved = (bool)ctlState[6];
         _addExchange = (bool)ctlState[7];
         _exchangeHeader = (Exchangepartheader)ctlState[8];
         _isVehicleOnTiptop = (bool)ctlState[9];
         _sVehicleType = (string)ctlState[10];
         _sVehileColor = (string)ctlState[11];
         _sVehicleDealer = (string)ctlState[12];
         _dtVehicleMadedate = (DateTime)ctlState[13];
         _editSheetId = (long)ctlState[14];
         _saveTemp = (bool)ctlState[15];
         _exchSaved = (bool)ctlState[16];
         _canChangeBuyDate = (bool)ctlState[17];
         _itemExist = (bool)ctlState[18];
         _sVehicleDB = (string)ctlState[19];
     }
 }
    /* tntung
     * End: Service Record Sheet
     */
    protected void btnNewCus_Click(object sender, EventArgs e)
    {
        #region copy from tnTung

        long lngCustId;
        long.TryParse(_CustomerID.Value, out lngCustId);
        string ActionString = "DEFAULT";

        ISession sess = NHibernateSessionManager.Instance.GetSession();
        IList lstCus = sess.CreateCriteria(typeof(Customer))
            .Add(Expression.Eq("Id", lngCustId))
            .Add(Expression.Eq("Dealercode", CurrentDealer)).List();
        if (lstCus.Count > 0)
        {
            ActionString = "UPDATECUSTOMER";
        }
        string idnum = txtCustId.Text.Trim();
        string fullname = _CustomerFullName.Value;
        bool gender;
        if (ddlSex.Value.Trim().Equals("1"))
        {
            gender = true;
        }
        else gender = false;

        DateTime dt;
        CultureInfo cultInfo = Thread.CurrentThread.CurrentCulture;
        DateTime.TryParse(txtBirthDate.Value, cultInfo, DateTimeStyles.AllowWhiteSpaces, out dt);
        DateTime birthdate = dt;

        string address = txtAddress.Value.Trim();
        string provinceid = ddlProvince.Value.ToString().Trim();
        string districtid = txtDistrict.Value.Trim();
        int jobtype = int.Parse(tblCus_JobType.Value.ToString());
        string email = txtCEmail.Value.Trim();
        //if (string.IsNullOrEmpty(email)) email = ".";
        string tel = txtCPhone.Value.Trim();
        string mobile = txtCMobile.Value.Trim();
        //if (string.IsNullOrEmpty(mobile)) mobile = ".";
        int priority = int.Parse(ddlCus_SetType.Value);
        string customertype = ddlCusType.Value;
        string cusdesc;
        if (txtCus_Desc.Value.Length > 1024)
        {
            cusdesc = txtCus_Desc.Value.Substring(0, 1024).Trim();
        }
        else cusdesc = txtCus_Desc.Value.Trim();
        string precinct = txtPrecinct.Value.Trim();

        //Save Customer
        ITransaction tx = sess.BeginTransaction();
        if (ActionString.Equals("UPDATECUSTOMER"))
        {
            lngCustId = CustomerHelper.UpdateCustomer(ref sess, lngCustId, idnum, fullname, gender, birthdate, address, provinceid, districtid, jobtype, email, tel, mobile, priority, customertype, cusdesc, precinct, CurrentDealer, true);
            _CustomerID.Value = lngCustId.ToString();
            txtCustId.Text = idnum;
            //lbCustomerFullName.Text = fullname;
        }
        else
        {
            lngCustId = CustomerHelper.SaveCustomer(ref sess, idnum, fullname, gender, birthdate, address, provinceid, districtid, jobtype, email, tel, mobile, priority, customertype, cusdesc, precinct, CurrentDealer, true);
            _CustomerID.Value = lngCustId.ToString();
            txtCustId.Text = idnum;
            //lbCustomerFullName.Text = fullname;
        }
        //btnSave.Enabled = true;

        #endregion

        // load cust info
        _custInfo = sess.Get<Customer>(lngCustId);
        //_custInfo = WarrantyContent.GetCustInfos(lngCustId);
        ShowCustInfo();
        tx.Commit();
    }
 // select a customer
 protected void Button1_Click(object sender, EventArgs e)
 {
     Button btn = (Button)sender;
     Customer cust = CustomerDataSource.GetCustomer(btn.CommandArgument);
     if (cust != null)
     {
         _custInfo = cust;
         ShowCustInfo();
     }
     SetAvtiveView(vwMainIndex);
 }
    private void ShowServiceSheet(bool readOnly, Serviceheader serH)
    {
        _finish = readOnly;
        readOnlyForm = readOnly;
        AddExchange1.readOnlyMode = readOnly;

        if (serH != null)
        {
            //_exchangeHeader = RepairListDataSource.GetExchangeHeaderFromServiceSheet(serH.Id);

            #region header section
            // warranty info
            // WarrantyInfo warrInfo = ServiceTools.GetWarrantyInfo(serH.Enginenumber);

            _sVehileColor = serH.Colorcode;
            _sVehicleDealer = serH.Dealercode;
            _sVehicleType = serH.Itemtype;
            _feeAmount = serH.Feeamount.ToString();

            txtSheetNo.Text = serH.Servicesheetnumber;
            txtEngineNo.Text = serH.Enginenumber;

            txtErrorStatus.Text = serH.Damaged;
            txtRepair.Text = serH.Repairresult;

            viewmodeDealer = serH.Dealercode;
            if (ListContainsValue(ddlDealer.Items, viewmodeDealer)) ddlDealer.SelectedValue = viewmodeDealer;
            else ddlDealer.Items.Clear();
            GetBranchs();

            btnCheck_Click(null, null); // donot clear
            EnableButtonAfterCheck(true, true);

            // service type
            bool maint = false, rep = false, warr = false;
            switch ((ServiceType)serH.Servicetype)
            {
                case ServiceType.Repair: rep = true; break;
                case ServiceType.Warranty: warr = true; break;
                case ServiceType.Maintain: maint = true; break;
                case ServiceType.MaintainAndRepair: maint = true; rep = true; break;
                case ServiceType.MaintainAndWarranty: maint = true; warr = true; break;
                case ServiceType.WarrantyAndRepair: warr = true; rep = true; break;
                case ServiceType.RepairAndMaintainAndWarranty: maint = true; rep = true; warr = true; break;
            }
            chblSerList.Items[0].Selected = maint; chblSerList.Items[1].Selected = rep; chblSerList.Items[2].Selected = warr;
            #endregion

            gvSpareList.DataSourceTable.Rows.Clear();

            #region repair section
            _feeAmount = serH.Feeamount.ToString();

            // service detail: spares
            RepairListDataSource ds = new RepairListDataSource();
            ArrayList serDs = ds.GetServiceDetails(serH.Id);
            for (int i = 0; i < serDs.Count; i++)
            {
                Servicedetail serD = (Servicedetail)serDs[i];
                DataRow row = gvSpareList.DataSourceTable.NewRow();
                Warrantycondition spareInfo = WarrantyContent.GetWarrantyCondition(serD.Partcode);

                row["SpareNo"] = i + 1;
                row["SpareNumber"] = serD.Partcode;
                row["Quantity"] = serD.Partqty;
                row["SpareCost"] = serD.Unitprice;
                row["IsExchangeSpare"] = string.Empty;
                row["ItemId"] = serD.Id;

                if (spareInfo != null)
                {
                    row["SpareNameEn"] = spareInfo.Partnameen;
                    row["SpareNameVn"] = spareInfo.Partnamevn;
                    row["SpareName"] = (Thread.CurrentThread.CurrentCulture.Name == "vi-VN") ? spareInfo.Partnamevn : spareInfo.Partnameen;
                }
                else
                {
                    row["SpareNameEn"] = serD.Partname;
                    row["SpareNameVn"] = serD.Partname;
                    row["SpareName"] = serD.Partname;
                }

                CalculateAmount(row, null);
                gvSpareList.DataSourceTable.Rows.Add(row);
            }
            #endregion

            #region exchangeSection
            if (ds == null) ds = new RepairListDataSource();
            Exchangepartheader exch = ds.GetExchangeHeader(serH.Id);
            _exchangeHeader = exch;
            if (exch != null)
            {
                AddExchange1.ExchangeHeader = _exchangeHeader;
                AddExchange1.InitUC();
                AddExchange1.SpareList.Rows.Clear();

                ArrayList exchDs = ds.GetExchangeDetails(exch.Id);
                AddExchange1.RawSpareList = AddExchange.SpareListOnServiceSchema;

                for (int i = 0; i < exchDs.Count; i++)
                {
                    Exchangepartdetail exchD = (Exchangepartdetail)exchDs[i];
                    Warrantycondition spareInfo = WarrantyContent.GetWarrantyCondition(exchD.Partcodem);

                    #region Display on SRS
                    DataRow row = gvSpareList.DataSourceTable.NewRow();
                    row["SpareNo"] = i + 1;
                    row["SpareNumber"] = exchD.Partcodem;
                    row["Quantity"] = exchD.Partqtym;
                    row["SpareCost"] = exchD.Unitpricem;
                    row["ExchangeNumber"] = exch.Vouchernumber;
                    row["IsExchangeSpare"] = "true";
                    row["ItemId"] = exchD.Id;
                    if (spareInfo != null)
                    {
                        row["SpareNameEn"] = spareInfo.Partnameen;
                        row["SpareNameVn"] = spareInfo.Partnamevn;
                        row["SpareName"] = (Thread.CurrentThread.CurrentCulture.Name == "vi-VN") ? spareInfo.Partnamevn : spareInfo.Partnameen;
                    }
                    else
                    {
                        row["SpareNameEn"] = Message.DataLost;
                        row["SpareNameVn"] = Message.DataLost;
                        row["SpareName"] = Message.DataLost;
                    }

                    //_feeAmount = exch.Feeamount.ToString();
                    //CalculateAmount(row, null);
                    gvSpareList.DataSourceTable.Rows.InsertAt(row, 0);
                    #endregion

                    #region display on PCV
                    row = AddExchange1.RawSpareList.NewRow();

                    row["ItemId"] = exchD.Id;
                    row["SpareNo"] = i + 1;
                    row["SpareNumber"] = exchD.Partcodem;
                    row["Quantity"] = exchD.Partqtym;
                    row["BrokenCode"] = exchD.Broken.Brokencode;
                    row["SerialNumber"] = exchD.Serialnumber;

                    AddExchange1.AddNewItem(row);
                    AddExchange1.RawSpareList.Rows.Add(row);
                    #endregion
                }
            }
            #endregion

            CalculateTotalAmount();
            gvSpareList.DataBind();
            CheckFinish();

            // cust info n' buy date
            _custInfo = serH.Customer;
            ShowCustInfo();
            txtRepairDate.Text = (serH.Servicedate > DateTime.MinValue) ? serH.Servicedate.ToShortDateString() : "";
        }
    }
    protected void btnCheck_Click(object sender, EventArgs e)
    {
        string newEngine = txtEngineNo.Text.Trim().ToUpper();
        if (hdEngineNumber.Value != newEngine) _custInfo = null;

        hdEngineNumber.Value = newEngine;
        SetReadOnly(txtNumberPlate, false);
        SetReadOnly(txtFrameNumber, false);
        SetReadOnly(txtBuyDate, false);
        SetReadOnly(ibtnCalendar, false);
        btnNewCus.Enabled = true;

        // clear form when check a enginenumber
        // (sender == null) => manual check from check finish => donot clear
        if (sender != null) { ClearForm(); }

        bool itemExist = CheckEngineNumber(hdEngineNumber.Value, (sender != null) && (e != null));

        EnableButtonAfterCheck(itemExist, sender != null);

        itemSelecting = false;
    }
Beispiel #6
0
 public static void SetSelectCusSession(string key, Customer val)
 {
     HttpContext.Current.Session[string.Format(PopupHelper.SelectCusSessionString, key)] = val;
 }
    // get item's info and fill to mainView.
    // rowIndex: index cua xe duoc chon tren selectItemGridview
    // ret true if vehicle exist in VDMS
    private bool GetItemInfo(string engineNum)
    {
        bool itemExist = false;
        bool tipTopHasThisItem = false;
        //string txt, txt2;
        //int i;

        ItemInstance iis = ItemInstanceDataSource.GetByEngineNumber(engineNum);
        // warranty info
        WarrantyInfo warrInfo = ServiceTools.GetWarrantyInfo(engineNum);

        // tim thong tin tu cac lan sua chua truoc
        Serviceheader serh = (_editSheetId > 0) ? WarrantyContent.GetServiceSheet(_editSheetId).ConvertServiceHeader() : WarrantyContent.FindServiceSheet(hdEngineNumber.Value).ConvertServiceHeader();

        // model and color ----------------------------------------------------------
        //if ((iis != null) || (serh != null))
        {
            #region Model - Color
            if ((iis == null) && (!_isVehicleOnTiptop) && (serh != null))
            {
                _sVehileColor = serh.Colorcode;
                _sVehicleType = serh.Itemtype;
            }

            // khong lay thong tin xe dc (rat kho, nhung da co :))
            if (iis != null)
            {
                if (string.IsNullOrEmpty(_sVehicleType)) _sVehicleType = iis.ItemType;
                if (string.IsNullOrEmpty(_sVehileColor)) _sVehileColor = iis.Color;
            }

            if (!_finishChecking)
            {
                txtModel.Text = _sVehicleType;

                if (string.IsNullOrEmpty(_sVehileColor))
                {
                    if (!_finishChecking) LoadAllColor();
                    ddlColour.Enabled = true;
                    ddlColour.SelectedIndex = 0;
                }
                else
                {
                    int i = GetItemsIndex(ddlColour.Items, _sVehileColor);
                    if (i >= 0)
                    {
                        ddlColour.SelectedIndex = i;
                        ddlColour.Enabled = false;
                    }
                    else if (!string.IsNullOrEmpty(_sVehileColor))
                    {
                        ddlColour.Items.Clear();
                        ddlColour.Items.Add(new ListItem(_sVehileColor, _sVehileColor));
                    }
                }
            }
            #endregion
        }

        // repair history----------------------------------------------------------
        #region repair history
        if ((serh != null) /*|| (iis != null)*/)
        {
            btnHistory.Enabled = true;
            btnHistory.OnClientClick = "window.open('repairhistory.aspx?engnum=" + engineNum + "','repairhis',''); return false;";
        }
        else
        {
            btnHistory.Enabled = false;
            btnHistory.OnClientClick = "";
        }

        // cust invoice info /*****/
        var cusInv = WarrantyContent.GetCustInvoiceInfos(engineNum);
        bool custInvNotExist = cusInv == null;
        #endregion

        // thong tin khach hang----------------------------------------------------------
        #region Customer
        if (_custInfo == null)
        {
            if (serh != null)
            {
                _custInfo = serh.Customer;
            }
            else if ((warrInfo != null) && (warrInfo.Customer != null))
            {
                _custInfo = warrInfo.Customer.ConvertCustomer();
            }
            else if (!custInvNotExist)
            {
                _custInfo = cusInv.Customer.ConvertCustomer();
            }
            else if (!_finishChecking) // lan dau tien nhap them KH (tru` luc chuan bi ket thuc: vua nhap KH xong => khong xoa)
            {
                txtCusName.Text = ""; txtCustAddress.Text = "";
                txtEmail.Text = ""; txtPhoneNo.Text = "";
            }
        }
        ShowCustInfo();
        #endregion

        // so khung, bien so ----------------------------------------------------------
        if ((serh != null) && (!_finishChecking))
        {
            if (!string.IsNullOrEmpty(serh.Framenumber)) txtFrameNumber.Text = serh.Framenumber;
            if (!string.IsNullOrEmpty(serh.Numberplate)) txtNumberPlate.Text = serh.Numberplate;
            SetReadOnly(txtNumberPlate, !string.IsNullOrEmpty(txtNumberPlate.Text));
            SetReadOnly(txtFrameNumber, !string.IsNullOrEmpty(txtFrameNumber.Text));
        }

        // get KmCount, buy date----------------------------------------------------------
        #region KM-Buy date
        if (serh != null)
        {
            if ((readOnlyForm || (_editSheetId > 0)) && (!_finishChecking))
            {
                txtKm.Text = serh.Kmcount.ToString();
            }
            txtLastKm.Text = (warrInfo != null) ? warrInfo.KmCount.ToString() : "";
        }
        else if (warrInfo != null)
        {
            txtLastKm.Text = warrInfo.KmCount.ToString();
        }
        else
        {
            txtLastKm.Text = "0";
        }

        DateTime buyDate = DateTime.MinValue;
        if (string.IsNullOrEmpty(txtBuyDate.Text))
        {
            if (warrInfo != null)
            {
                buyDate = warrInfo.PurchaseDate;
            }
            else if (!custInvNotExist)
            {
                buyDate = cusInv.SellDate;
            }
            else if (serh != null)
            {
                buyDate = serh.Purchasedate;
            }
        }
        if (buyDate > DateTime.MinValue) txtBuyDate.Text = buyDate.ToShortDateString();
        #endregion

        // lay duoc thong tin xe tren tiptop => thoi ko alarm nua
        itemExist = (iis != null) || tipTopHasThisItem || _isVehicleOnTiptop;
        _canChangeBuyDate = (!itemExist) || (buyDate == DateTime.MinValue);

        //// canh bao xe chua duoc ban
        //if ((iis != null) && (iis.Status != (int)ItemStatus.Sold))
        //{
        //    AddError(WarrantyContentErrorCode.ItemNotSold);
        //}
        //else

        // canh bao dai ly ban xe va dai ly sua la khac nhau
        if ((_sVehicleDealer != CurrentDealer) && (!readOnlyForm) && (itemExist))
        {
            AddError(WarrantyContentErrorCode.ItemSoldByOtherDealer);
        }

        _itemExist = itemExist;
        return itemExist;
    }
    protected void InsertData(object sender, EventArgs e)
    {
        if (!CusInfph.Visible) { CusInfph.Visible = true; return; }
        string ActionString = "DEFAULT";
        ISession sess = NHibernateSessionManager.Instance.GetSession();
        string EngNo = txtEngineNumberInput.Text.Trim();
        Customer cusIns = new Customer();
        if (long.Parse(_CustomerID.Value) > 0)
            cusIns.Id = long.Parse(_CustomerID.Value);

        DateTime pDate;
        DateTime.TryParse(txtPurchaseDateInput.Text.Trim(), new CultureInfo(UserHelper.Language),
                          DateTimeStyles.AllowWhiteSpaces, out pDate);
        if (pDate.Equals(DateTime.MinValue))
        {
            ShowMessage(Message.WarrantyInfo_PurchaseDateInvalid, true); return;
        }
        IList lstCus = sess.CreateCriteria(typeof(Customer))
            .Add(Expression.Eq("Id", long.Parse(_CustomerID.Value)))
            .Add(Expression.Eq("Forservice", true))
            .List();
        if (lstCus.Count > 0)
        {
            cusIns = lstCus[0] as Customer;
            ActionString = "UPDATECUSTOMER";
        }
        DateTime dt;
        CultureInfo cultInfo = Thread.CurrentThread.CurrentCulture;
        DateTime.TryParse(txtBirthDateInput.Text, cultInfo, DateTimeStyles.AllowWhiteSpaces, out dt);
        if (dt.Equals(DateTime.MinValue) && !txtBirthDateInput.Text.Trim().Equals(""))
        {
            ShowMessage(Customers.BirthDateInvalid, true);
        }
        //DateTime birthdate = dt;
        cusIns.Birthdate = dt;

        //string idnum = txtCustomerIDInput.Text.Trim();
        cusIns.Identifynumber = txtCustomerIDInput.Text.Trim();
        //string fullname = txtCusNameInput.Text;
        cusIns.Fullname = txtCusNameInput.Text;
        bool gender;
        if (ddlSexInput.SelectedValue.Trim() == "1")
        {
            gender = true;
        }
        else gender = false;
        cusIns.Gender = gender;
        //string address = txtAddressInput.Text.Trim();
        //string precinct = txtPrecinctInput.Text.Trim();
        //string districtid = txtDistrictInput.Text.Trim();
        //string provinceid = ddlProvinceInput.SelectedValue.Trim();
        cusIns.Address = txtAddressInput.Text.Trim();
        cusIns.Precinct = txtPrecinctInput.Text.Trim();
        cusIns.Districtid = txtDistrictInput.Text.Trim();
        cusIns.Provinceid = ddlProvinceInput.SelectedValue.Trim();

        //int jobtype = int.Parse(tblCus_JobType.SelectedValue);
        cusIns.Jobtypeid = int.Parse(tblCus_JobType.SelectedValue);
        //string email = txtEmail.Text.Trim();
        cusIns.Email = txtEmail.Text.Trim();
        //string tel = txtPhone.Text.Trim();
        cusIns.Tel = txtPhone.Text.Trim();
        //string mobile = txtMobile.Text.Trim();
        cusIns.Mobile = txtMobile.Text.Trim();
        //int priority = int.Parse(ddlCus_SetType.SelectedValue);
        //string customertype = ddlCusType.SelectedValue;
        cusIns.Priority = int.Parse(ddlCus_SetType.SelectedValue);
        cusIns.Customertype = int.Parse(ddlCusType.SelectedValue);
        if (txtCus_Desc.Text.Length > 1024)
        {
            cusIns.Customerdescription = txtCus_Desc.Text.Substring(0, 1024).Trim();
        }
        else cusIns.Customerdescription = txtCus_Desc.Text.Trim();

        //static field
        cusIns.Dealercode = ddlDealerCode.SelectedValue;
        if (ActionString != "UPDATECUSTOMER") cusIns.Forservice = true;

        //Save Customer
        using (ITransaction tx = sess.BeginTransaction())
        {
            tx.Begin();
            sess.SaveOrUpdate(cusIns);
            if (ServiceTools.SaveWarrantyInfo(EngNo, -1, DateTime.MinValue,
                    null, null, null, null, cusIns.Id) == false)
            {
                tx.Rollback();
                ShowMessage(Message.WarrantyContent_UpdateDataFailed, true);
                btnInsertCus.Enabled = true;
            }
            else
            {
                tx.Commit();
                ShowMessage(Message.ActionSucessful, false);
                btnInsertCus.Enabled = false;
            }
        }

        InputGUIDisplay(false);
        gvItem.DataBind();
    }
    private void BindCustomer(Customer cusGet)
    {
        CusInfph.Visible = cusGet != null;
        if (cusGet != null)
        {
            _CustomerID.Value = cusGet.Id.ToString();
            txtCustomerIDInput.Text = cusGet.Identifynumber;
            txtCusNameInput.Text = cusGet.Fullname;
            if (!DateTime.MinValue.Equals(cusGet.Birthdate))
            {
                txtBirthDateInput.Text = cusGet.Birthdate.ToShortDateString();
            }

            txtAddressInput.Text = cusGet.Address;
            txtPrecinctInput.Text = cusGet.Precinct;
            txtDistrictInput.Text = cusGet.Districtid;
            ddlSexInput.SelectedValue = (cusGet.Gender) ? "1" : "0";
            try
            {
                if (!String.IsNullOrEmpty(cusGet.Provinceid))
                    ddlProvinceInput.SelectedValue = cusGet.Provinceid;
            }
            catch (Exception)
            {
                ddlProvinceInput.SelectedIndex = 0;
            }
        }
    }
Beispiel #10
0
        public static bool SaveWarrantyInfo(string engine, int Km, DateTime buyDate, string database, string itemCode, string color, string sellDealer, long custID, Customer initCus)
        {
            bool result = false;
            Warrantyinfo warrInfo;
            IDao<Warrantyinfo, string> dao = DaoFactory.GetDao<Warrantyinfo, string>();
            IDao<Customer, long> daoCust;

            try
            {
                warrInfo = dao.GetById(engine, false); //true -> false
                bool newItem = warrInfo == null;
                if (newItem)
                {
                    warrInfo = new Warrantyinfo();
                    warrInfo.Id = engine;
                    warrInfo.Createdate = DateTime.Now;
                    warrInfo.CreateByDealer = VDMS.Helper.UserHelper.DealerCode;
                    warrInfo.Status = WarrantyInfoStatus.New;
                }
                if (Km >= 0) warrInfo.Kmcount = Km;
                if (!DateTime.MinValue.Equals(buyDate)) warrInfo.Purchasedate = buyDate;
                if (!string.IsNullOrEmpty(sellDealer)) warrInfo.Selldealercode = sellDealer;

                // for first time init warrInfo by SRS: copy customer
                if ((warrInfo.Customer == null) && (initCus != null)) warrInfo.Customer = initCus;
                // main customer
                if (custID > 0)
                {
                    daoCust = DaoFactory.GetDao<Customer, long>();
                    Customer cust = daoCust.GetById(custID, false);
                    if (cust != null) warrInfo.Customer = cust;
                }

                if (!string.IsNullOrEmpty(database)) warrInfo.Databasecode = database;
                if (!string.IsNullOrEmpty(color)) warrInfo.Color = color;
                if (!string.IsNullOrEmpty(itemCode)) warrInfo.Itemcode = itemCode;

                if (newItem)
                    dao.Save(warrInfo);
                else
                    dao.SaveOrUpdate(warrInfo);
                result = true;
            }
            catch
            {
            }

            return result;
        }
Beispiel #11
0
 public static string GetCustTelNo(Customer cst)
 {
     if (cst == null) return "";
     return (string.IsNullOrEmpty(cst.Mobile)) ? cst.Tel : cst.Mobile;
 }
Beispiel #12
0
 public static string GetCustAddress(Customer cst)
 {
     if (cst == null) return "";
     string address = cst.Address, province = ProvinceHelper.GetProvinceName(cst.Provinceid);
     address += (string.IsNullOrEmpty(cst.Precinct) ? "" : ((string.IsNullOrEmpty(address)) ? "" : " - ") + cst.Precinct);
     address += (string.IsNullOrEmpty(cst.Districtid) ? "" : ((string.IsNullOrEmpty(address)) ? "" : " - ") + cst.Districtid);
     address += (string.IsNullOrEmpty(province) ? "" : ((string.IsNullOrEmpty(address)) ? "" : " - ") + province);
     return address;
 }
        public static Serviceheader SaveSerHeader(long sheetId, ServiceStatus status, string dealer, string branch, string enNum, string plateNum, string frameNum, string model, string color, string err, string solution, string exchangeNum, int serType, Customer cust, long km, long fee, long total, DateTime serDate, DateTime buyDate, out WarrantyContentErrorCode errCode)
        {
            errCode = WarrantyContentErrorCode.SaveHeaderFailed;

            if (string.IsNullOrEmpty(dealer) || string.IsNullOrEmpty(branch)) return null;

            Serviceheader serH = null;
            if (
                ((!string.IsNullOrEmpty(err.Trim()))
                && (cust != null)
                && (!string.IsNullOrEmpty(model))
                && (!string.IsNullOrEmpty(color)))
                ||
                (status < 0)
                )
            {
                IDao<Serviceheader, long> dao = DaoFactory.GetDao<Serviceheader, long>();

                serH = dao.GetById(sheetId, false); //true -> false
                if (serH == null)
                {
                    serH = new Serviceheader();
                }

                serH.Branchcode = branch;
                serH.Customer = cust;
                serH.Colorcode = color;
                serH.Damaged = err.Trim();
                serH.Dealercode = dealer;
                serH.Enginenumber = enNum.Trim().ToUpper();
                serH.Feeamount = fee;
                serH.Framenumber = frameNum;
                serH.Itemtype = model;
                serH.Kmcount = km;
                serH.Numberplate = plateNum.Trim().ToUpper();
                serH.Purchasedate = buyDate;
                serH.Repairresult = solution.Trim();
                serH.Servicedate = serDate;
                serH.Servicesheetnumber = GenSheetNumber(status == ServiceStatus.Temp, dealer);
                serH.Servicetype = serType;
                serH.Totalamount = total;
                serH.Status = (int)status;
                serH.Createby = UserHelper.Username;

                try { dao.SaveOrUpdate(serH); }
                catch { serH = null; }
            }

            errCode = WarrantyContentErrorCode.OK;
            return serH;
        }
    private void InsertNewData(ref ISession sess)
    {
        //if (checkDateRange(txtSellingDate.Text.Trim(), txtRecCDate.Text.Trim())) { ShowMessage(Resources.Customers.RecDateSmallerThanSelDate, true); return; }
        //Datetime
        DateTime dtRecDate = DataFormat.DateFromString(txtRecCDate.Text), dtSellDate = DataFormat.DateFromString(txtSellingDate.Text);

        string PriceTax;
        PriceTax = txtPriceTax.Text.Trim().Replace(",", "");
        PriceTax = txtPriceTax.Text.Trim().Replace(".", "");

        ITransaction tx = sess.BeginTransaction();
        try
        {
            string Billno = txtBillNo.Text.Trim();
            //string idnum = _CustomerID.Value.Trim();
            if (_CustomerID.Value.Trim() == "-1")
            {
                ShowMessage(Message.Cus_NoCustomer, true);
                return;
            }
            Invoice InvoiceIns = new Invoice();
            // so hoa don giua 2 dai ly co the trung
            IList lstNonDulpInvoiceIns = sess.CreateCriteria(typeof(Invoice))
                .Add(Expression.Eq("Invoicenumber", Billno))
                .Add(Expression.Eq("Dealercode", UserHelper.DealerCode))
                .List();
            if (lstNonDulpInvoiceIns.Count > 0)
            {
                ShowMessage(Customers.Invoice_BillDuplicated, true);
                return;
            }
            else
            {
                lstNonDulpInvoiceIns = sess.CreateCriteria(typeof(Invoice))
                    .Add(Expression.InsensitiveLike("Enginenumber", txtEngineNo.Text.Trim().ToUpper()))
                    //.Add(Expression.Eq("Dealercode", UserHelper.DealerCode))
                    .List();
                if (lstNonDulpInvoiceIns.Count > 0)
                {
                    ShowMessage(Customers.Invoice_BillDuplicated, true);
                    return;
                }
                else InvoiceIns.Invoicenumber = Billno;
            }

            //Begin: Update SellItem
            Sellitem SellItemIns = new Sellitem();
            SellItemIns.Numberplate = txtPlateNo.Text.Trim();
            SellItemIns.Selltype = txtSellingType.Text.Trim();
            SellItemIns.Pricebeforetax = (!PriceTax.Equals("")) ? decimal.Parse(PriceTax) : 0;
            SellItemIns.Paymenttype = int.Parse(ddlPaymentMethod.SelectedValue);

            if (txtTakPlateNoDate.Text.Trim() != "")
            {
                SellItemIns.Numplaterecdate = DataFormat.DateFromString(txtTakPlateNoDate.Text);
            }
            else SellItemIns.Numplaterecdate = DateTime.MinValue;

            SellItemIns.Paymentdate = dtRecDate;
            SellItemIns.Commentsellitem = txtComment.Text.Trim();
            sess.SaveOrUpdate(SellItemIns);
            InvoiceIns.Sellitem = SellItemIns;
            //End: Update SellItem
            //Begin: Save Payment Method
            if (ddlPaymentMethod.SelectedValue.Equals(((int)CusPaymentType.UnFixedHire_purchase).ToString()))
            {
                TextBox txtIntentDatePay, UHPtxtMoney;
                Payment pmIns;
                for (int i = 1; i < 6; i++)
                {
                    try
                    {
                        txtIntentDatePay = (TextBox)UnfixedHP.FindControl("txtIntentDatePay" + i);
                        UHPtxtMoney = (TextBox)UnfixedHP.FindControl("UHPtxtMoney" + i);
                        pmIns = new Payment();
                        if (txtIntentDatePay.Text.Trim() != "" && UHPtxtMoney.Text.Trim() != "")
                        {
                            pmIns.Sellitem = SellItemIns;
                            pmIns.Paymentdate = DateTime.Parse(txtIntentDatePay.Text.Trim());
                            pmIns.Amount = decimal.Parse(UHPtxtMoney.Text.Trim());
                            pmIns.Status = 0;
                            sess.Save(pmIns);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            if (ddlPaymentMethod.SelectedValue.Equals(((int)CusPaymentType.FixedHire_purchase).ToString()))
            {
                BindAndSaveFHPPayment(ref sess, SellItemIns);
            }
            //End: Save Payment Method
            //Begin: Update ItemInstance
            Iteminstance ItmIns = sess.CreateCriteria(typeof(Iteminstance))
                                      .Add(Expression.Eq("Id", Int64.Parse(_ItemInstanceID.Value))).List()[0] as
                                  Iteminstance;
            ItmIns.Status = (int)ItemStatus.Sold;
            ItmIns.Releaseddate = dtSellDate;
            sess.SaveOrUpdate(ItmIns);
            if (PriceTax.Equals("")) PriceTax = "0";
            TransHis th =
                (new ItemHepler()).SaveTranHis(ItmIns, dtSellDate, ItemStatus.Sold,
                                               int.Parse(ddlPaymentMethod.SelectedValue), decimal.Parse(PriceTax),
                                               UserHelper.Username, null, UserHelper.FullBranchCode, null);
            sess.Save(th);

            // save to Inventory of Day
            InventoryHelper.SaveInventoryDay(ItmIns.Item.Id, dtSellDate, -1, (int)ItemStatus.Sold,
                                             UserHelper.DealerCode, UserHelper.BranchCode);

            InvoiceIns.Iteminstance = ItmIns;
            //End: Update ItemInstance
            //Begin: Customer Type
            Customer cusIns =
                sess.CreateCriteria(typeof(Customer)).Add(Expression.Eq("Id", Int64.Parse(_CustomerID.Value)))
                .List()[0] as Customer;
            InvoiceIns.Customer = cusIns;

            InvoiceIns.Enginenumber = ItmIns.Enginenumber;
            InvoiceIns.Dealercode = ItmIns.Dealercode;
            InvoiceIns.Branchcode = ItmIns.Branchcode;
            InvoiceIns.Createddate = DateTime.Now;
            InvoiceIns.Selldate = dtSellDate;
            InvoiceIns.Createdby = UserHelper.Username;
            sess.SaveOrUpdate(InvoiceIns);

            #region warrantyInfo
            //********** Save warranty info ***************
            WarrantyInfo warr = ServiceTools.GetWarrantyInfo(ItmIns.Enginenumber);
            if (warr == null)   // co roi thi thoi: yeu cau ngay 16/7/2008
            {
                //Clone new customer
                Customer csnew = new Customer(cusIns.Identifynumber, cusIns.Fullname, cusIns.Gender, cusIns.Birthdate, cusIns.Address, cusIns.Provinceid, cusIns.Districtid, cusIns.Jobtypeid, cusIns.Email, cusIns.Tel, cusIns.Mobile, (int)CusType.WarrantyInfo, cusIns.Customerdescription, cusIns.Precinct, cusIns.Priority, cusIns.Dealercode, false);
                sess.Save(csnew);

                if (ServiceTools.SaveWarrantyInfo(ItmIns.Enginenumber, 0, dtSellDate,
                ItmIns.Databasecode, ItmIns.Item.Id, ItmIns.Color, UserHelper.DealerCode, csnew.Id) == false)
                {
                    throw new Exception(Message.WarrantyContent_UpdateDataFailed);
                }
            }
            #endregion

            tx.Commit();
            ShowMessage(Message.ActionSucessful, false);

            RefreshAll();
            _PageStatus.Value = _DEFAULTPAGE;
        }
        catch (Exception ex)
        {
            if (!tx.WasRolledBack)
                tx.Rollback();
            ShowMessage(ex.Message, true);
        }
    }